# test that lammpslib handle nonperiodic cases where the cell size
# in some directions is small (for example for a dimer).
from __future__ import print_function
import os
import numpy as np
from ase.calculators.lammpslib import LAMMPSlib
from ase import Atoms

potential_path = os.environ.get('LAMMPS_POTENTIALS_PATH', '.')
cmds = ["pair_style eam/alloy",
        "pair_coeff * * {path}/NiAlH_jea.eam.alloy Ni H"
        "".format(path=potential_path)]
lammps = LAMMPSlib(lmpcmds=cmds,
                   atom_types={'Ni': 1, 'H': 2},
                   log_file='test.log', keep_alive=True)
a = 2.0
dimer = Atoms("NiNi", positions=[(0,0,0),(a,0,0)],
              cell=(1000*a, 1000*a, 1000*a),pbc=(0,0,0))
dimer.set_calculator(lammps)

energy_ref = -1.10756669119
energy = dimer.get_potential_energy()
print("Computed energy: {}".format(energy))
diff = abs((energy - energy_ref) / energy_ref)
np.testing.assert_allclose(energy, energy_ref, atol=1e-10)

np.set_printoptions(precision=16)
forces_ref = np.array([[-0.9420162329811532, 0., 0.],[ 0.9420162329811532, 0., 0. ]])
forces = dimer.get_forces()
print(np.array2string(forces))
np.testing.assert_allclose(forces, forces_ref, atol=1e-10)
